package com.google.code.p.ivans.entities;

import java.io.Serializable;
import java.util.Calendar;
import java.util.GregorianCalendar;


public class Waiter implements Serializable {	
	
	private static final long serialVersionUID = -2265313400860903481L;
	
	public static final transient int ID_UPDATE = 1;
	public static final transient int FIRSTNAME_UPDATE = 2;
	public static final transient int LASTNAME_UPDATE = 3;
	public static final transient int PATRONYMICNAME_UPDATE = 4;
	public static final transient int BORN_DAY_UPDATE = 5;
	public static final transient int BORN_MONTH_UPDATE = 6;
	public static final transient int BORN_YEAR_UPDATE = 7;
	public static final transient int HIRE_DAY_UPDATE = 8;
	public static final transient int HIRE_MONTH_UPDATE = 9;
	public static final transient int HIRE_YEAR_UPDATE = 10;
	public static final transient int SALARY_UPDATE = 11;	
	
	private static transient long counter = 1;
	private static final transient int MIN_SALARY = 5500;
	private static final transient int MAX_SALARY = 100000;
	
	private long id;
	private String firstName;
	private String lastName;
	private String patronymicName;
	private GregorianCalendar bornDate;
	private GregorianCalendar hireDate;
	private int salary;
	
	
	
	public Waiter() {}
	
	public Waiter(String first, String last, String patronymic, GregorianCalendar born, GregorianCalendar hire, int salary) {
		
		if(first.length() == 0)
			throw new IllegalArgumentException("FirstName is empty");
		
		if(last.length() == 0)
			throw new IllegalArgumentException("LastName is empty");

		if(patronymic.length() == 0)
			throw new IllegalArgumentException("PatronymicName is empty");
		
		//���� ���� ������ ��������
		if(born.after(new GregorianCalendar()))
			throw new IllegalArgumentException("BornDate after nowaday");
		
		if(hire.after(new GregorianCalendar()))
			throw new IllegalArgumentException("HireDate after nowaday");
		
		if(salary < MIN_SALARY || salary > MAX_SALARY)
			throw new IllegalArgumentException("Salary is out of bounds");
		
		this.id = counter++;
		this.firstName = first;
		this.lastName = last;
		this.patronymicName = patronymic;	
		this.bornDate = born;
		this.hireDate = hire;
		this.salary = salary;
	}
	
public Waiter(long id, String first, String last, String patronymic, GregorianCalendar born, GregorianCalendar hire, int salary) {
		
		if(first.length() == 0)
			throw new IllegalArgumentException("FirstName is empty");
		
		if(last.length() == 0)
			throw new IllegalArgumentException("LastName is empty");

		if(patronymic.length() == 0)
			throw new IllegalArgumentException("PatronymicName is empty");
		
		//���� ���� ������ ��������
		if(born.after(new GregorianCalendar()))
			throw new IllegalArgumentException("BornDate after nowaday");
		
		if(hire.after(new GregorianCalendar()))
			throw new IllegalArgumentException("HireDate after nowaday");
		
		if(salary < MIN_SALARY || salary > MAX_SALARY)
			throw new IllegalArgumentException("Salary is out of bounds");
		
		this.id = id;
		this.firstName = first;
		this.lastName = last;
		this.patronymicName = patronymic;	
		this.bornDate = born;
		this.hireDate = hire;
		this.salary = salary;
	}
	
	//get waiterID
	public long getId() {
		return id;
	}	
	
	//get/set firstName
	public String getFirstName() {
		return firstName;
	}
	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}
	
	//get/set patronymicName
	public String getPatronymicName() {
		return patronymicName;
	}
	public void setPatronymicName(String patronymicName) {
		this.patronymicName = patronymicName;
	}
	
	//get/set bornDate
	public GregorianCalendar getBornDate() {
		return bornDate;
	}
	public void setBornDate(GregorianCalendar bornDate) {
		this.bornDate = bornDate;
	}
	
	//get/set hireDate
	public GregorianCalendar getHireDate() {
		return hireDate;
	}
	public void setHireDate(GregorianCalendar hireDate) {
		this.hireDate = hireDate;
	}
	
	//get/set salary
	public int getSalary() {
		return this.salary;
	}
	public void setSalary(int salary) {
		this.salary = salary;
	}

	//get/se lastNAme
	public String getLastName() {
		return lastName;
	}

	public void setLastName(String lastName) {
		this.lastName = lastName;
	}	
	
	public String toString() {
		return  "ID: " + id + 
				"\n���: " + lastName + " " + firstName + " " + patronymicName + 
				"\n���� ��������: " + bornDate.get(Calendar.DAY_OF_MONTH)   + "-" + bornDate.get(Calendar.MONTH) + "-" + bornDate.get(Calendar.YEAR) + 
				"\n���� ��������: " + hireDate.get(Calendar.DAY_OF_MONTH)   + "-" + hireDate.get(Calendar.MONTH) + "-" + hireDate.get(Calendar.YEAR) +
				"\n��������: " + salary;
	}
	
	public static long getNewID() {
		return counter++;
	}
	
	public static void setCounter(long c) {
		counter = c;
	}
	
	public static long getCounter() {
		return counter;
	}
	
}
